from google.appengine.ext import db
from google.appengine.tools import bulkloader
from framework.models import *


def get_cdn(name):
    cdns = db.GqlQuery("select * from CDN where id = :1", name)
    if cdns.count() != 0:
        return cdns[0]

def get_framework(name):
    frameworks = db.GqlQuery("select * from Framework where id = :1", name)
    if frameworks.count() != 0:
        return frameworks[0]

        
class PlacementLoader(bulkloader.Loader):
  def __init__(self):
    bulkloader.Loader.__init__(self, 'Placement',
                               [
                                ("cdn", get_cdn),
                                ("framework", get_framework),
                                ('url', str),
                               ])

loaders = [PlacementLoader]